package org.csu.mypetstore.controller;

import org.csu.mypetstore.domain.Order;
import org.csu.mypetstore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/mOrder")
public class MorderController {

    @Autowired
    OrderService orderService;

    @GetMapping("/viewShowOrder")
    public String viewShowUser(String choice, Model model){
        List<Order> orderList=orderService.getOrder();
        model.addAttribute("orderList",orderList);
        model.addAttribute("choice",choice);
        System.out.println(orderList.get(0).getUsername()+"正在编辑订单信息"+choice);
        return "seller/mOrder/showOrder";
    }

    @RequestMapping(value="/searchOrder", method= RequestMethod.POST)
    private String doSearchOrders(@RequestParam("keyword") String keyword, Model model) {
        if(keyword!=null) {
            List<Order> orderList = orderService.searchOrderList(keyword);
            model.addAttribute("orderList",orderList);
            return "seller/mOrder/showOrder";
        }
        return "seller/mOrder/showCategory";
    }

}
